import { lazy, Suspense } from "react";
// 引入Router
import { createBrowserRouter } from "react-router";

// 引入组件
import Layout from "../pages/Layout";
import Login from "../pages/Login";
//import Home from "../pages/Home";
//import Article from "../pages/Article";
//import Publish from "../pages/Publish";
const Home = lazy(() => import("../pages/Home"));
const Article = lazy(() => import("../pages/Article"));
const Publish = lazy(() => import("../pages/Publish"));

// 引入AuthRouter组件（路由守卫）
import { AuthRouter } from "../components/AuthRouter";

const router = createBrowserRouter([
  {
    path: "/",
    // 使用AuthRouter组件（路由守卫）包裹Layout组件，判断是否登录，未登录则跳转到登录页
    element: <AuthRouter Children={<Layout />} />,
    children: [
      {
        index: true,
        element: (
          <Suspense fallback={"记载中"}>
            <Home />,
          </Suspense>
        ),
      },
      {
        path: "/article",
        element: (
          <Suspense fallback={"记载中"}>
            <Article />,
          </Suspense>
        ),
      },
      {
        path: "/publish",
        element: (
          <Suspense fallback={"记载中"}>
            <Publish />,
          </Suspense>
        ),
      },
    ],
  },
  {
    path: "/login",
    element: <Login />,
  },
]);

export default router;
